const mongoose = require("mongoose");
const Schema = mongoose.Schema;
mongoose.connect("mongodb://localhost:27017/supermark", {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

let userSchema = new Schema({
  email: {
    type: String,
    required: true,
  },
  nickname: {
    type: String,
    required: true,
  },
  iphone: {
    type: String,
  },
  password: {
    type: String,
    required: true,
  },
  address: {
    type: String,
  },
  created_time: {
    type: Date,
    //不能直接写Date.now() ，会直接调用
    //这样就写死了，值会一直是new 这个model时的时间
    default: Date.now,
  },
  last_modified_time: {
    type: Date,
    default: Date.now,
  },
  avater: {
    type: String,
    default: "/public/img/avatar-default.png",
  },
  bio: {
    type: String,
    default: "",
  },
  gender: {
    type: Number,
    enum: [-1, 0, 1],
    default: -1,
  },
  birthday: {
    type: Date,
  },
  signature: {
    type: String,
    defalut: "写个个性签名吧",
  },
  money: {
    type: Number,
    default: 0,
  },
  status: {
    type: Number,
    //0正常
    //1是否可以评论
    //2是否可以登录
    enum: [0, 1, 2],
    default: 0,
  },
});
module.exports = mongoose.model("User", userSchema);
